(function (fruit, util, global) {
    var document = global.document;
    //thanks to extjs
    var na = global.navigator,
        ua = na.userAgent.toLowerCase();

    function check(regex) {
        return regex.test(ua);
    }

    function version(is, regex) {
        var m;
        return (is && (m = regex.exec(ua))) ? parseFloat(m[1]) : 0;
    }

    util.extend(fruit, {
        os:(function () {
            var OS = {
                platform:na.platform
            };
            var whichOs = {
                Windows:/windows|win32/,
                Mac:/macintosh|mac os x/,
                Linux:/linux/
            };
            for (var key in whichOs) {
                if (OS['is' + key] = check(whichOs[key])) {
                    break;
                }
            }
            return OS;
        }()),
        browser:(function () {
            var compatMode = document.compatMode,
                Browser = {
                    compatMode:compatMode,
                    isStrict:compatMode === 'CSS1Compat'
                };
            var whichBrowser = [
                {
                    name:'ie',
                    is:'msie',
                    exclude:'opera',
                    version:'msie '
                },
                {
                    name:'firefox',
                    is:'gecko',
                    exclude:'webkit',
                    version:'\\bfirefox\/'
                },
                {
                    name:'chrome',
                    is:'\\bchrome\\b',
                    exclude:null,
                    version:'\\bchrome\/'
                },
                {
                    name:'safari',
                    is:'safari',
                    exclude:'\\bchrome\\b',
                    version:'version\/'
                },
                {
                    name:'opera',
                    is:'opera',
                    exclude:null,
                    version:'version\/'
                }
            ];
            var i, item, is, isBrowser, rVersion;
            for (i = 0; item = whichBrowser[i]; i++) {
                is = item.is ? check(new RegExp(item.is)) : true;
                isBrowser = !check(new RegExp(item.exclude)) && is;
                rVersion = new RegExp(item.version + '(\\d+\\.\\d+)');
                if (isBrowser) {
                    Browser[item.name] = version(is, rVersion);
                    break;
                }
            }
            if (Browser.ie) {
                Browser['docMode'] = document.documentMode;
            }
            if (na.vendor) {
                Browser['webkit'] = version(true, /webkit\/(\d+\.\d+)/);
            }
            return Browser;
        }())
    });
})(fruit, fruit.util, window);